package com.hc.javabasestudyproject.feature.stream;

import com.hc.javabasestudyproject.feature.entity.Author;
import com.hc.javabasestudyproject.feature.entity.Book;
import com.hc.javabasestudyproject.feature.entity.DataUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * @Author: huangcheng
 * @CreateTime: 2023-11-22  16:21
 * @Description:
 * @Version: 1.0
 */
public class MapStream {
    public static void main(String[] args) {
        List<Author> datalist = DataUtils.getAuthors();

        IntStream intStream = datalist.stream().mapToInt(Author::getAge);
        intStream.forEach(System.out::println);

        List<Book> collect = datalist.stream()
                .flatMap(data -> data.getBooks().stream()).collect(Collectors.toList());
        collect.forEach(System.out::println);

        List<String> collect1 = datalist.stream()
                .flatMap(author -> author.getBooks().stream())
                .flatMap(book -> Arrays.stream(book.getCategory().split(",")))
                .collect(Collectors.toList());
        collect1.forEach(System.out ::println);
    }
}
